//
//  DoublepickerViewController.m
//  10802pickerhomework
//
//  Created by 小白 on 16/2/23.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "DoublepickerViewController.h"

@interface DoublepickerViewController ()<UIPickerViewDataSource,UIPickerViewDelegate,UIAlertViewDelegate>
@property (nonatomic,strong) NSArray *leftList;
@property (nonatomic,strong) NSArray *rightList;
@property (nonatomic,strong) NSString *left;
@property (nonatomic,strong) NSString *right;

@end

@implementation DoublepickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.pickView.dataSource = self;
    self.pickView.delegate = self;
    self.leftList = @[@"火鸡"@"花生酱",@"金枪鱼沙拉",@"鸡丁沙拉",@"烤牛肉",@"蔬菜"];
    self.rightList = @[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包",@"天然有机谷物"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
// returns the number of 'columns' to display.
//返回列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

// returns the # of rows in each component..
//返回每列的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0) {
        return self.leftList.count;
    }
    else
    {
        return self.rightList.count;
    }
}
// these methods return either a plain NSString, a NSAttributedString, or a view (e.g UILabel) to display the row for the component.
//返回任意类型的row的值
- (nullable NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0) {
        return self.leftList[row];
    }
    else
    {
        return self.rightList[row];
    }
}
//picker变化事件
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0) {
        self.left = self.leftList[row];
    }
    else
    {
        self.right = self.rightList[row];
    }
   // self.labelinfo.text = [NSString stringWithFormat:@"您选择了%@和%@",self.left,self.right];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPress:(id)sender {
    NSString *str = [NSString stringWithFormat:@"您选择了%@和%@",self.left,self.right];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:str delegate:self cancelButtonTitle:@"重选" otherButtonTitles:@"确定", nil];
    [alert show];

    //self.labelinfo.text = str;

}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        self.labelinfo.text = [NSString stringWithFormat:@"早餐点了%@和%@",self.left,self.right];

    }
}
@end

